﻿Imports Microsoft.Practices.Composite.Modularity
Imports Microsoft.Practices.Unity
Imports Infragistics.Windows.Ribbon
Imports Microsoft.Practices.Composite.Regions
Imports Hinshelwood.TFSStickyBuddy.Infrastructure
Imports Hinshelwood.TFSStickyBuddy.Modules.Interfaces
Imports Hinshelwood.TFSStickyBuddy.Modules.PresentationModels
Imports Hinshelwood.TFSStickyBuddy.Modules.Presenters
Imports Hinshelwood.TFSStickyBuddy.Modules.Controllers
Imports Hinshelwood.TFSStickyBuddy.Modules.Services
Imports Hinshelwood.TFSStickyBuddy.Modules.Views

'Imports StockTraderRI.Infrastructure.Interfaces
'Imports StockTraderRI.Modules.News.Article
'Imports StockTraderRI.Modules.News.Controllers
'Imports StockTraderRI.Modules.News.Services

Public Class TeamSystemModule
    Implements IModule

    Private ReadOnly m_container As IUnityContainer
    Private ReadOnly m_rmShell As IRegionManager
    Private ReadOnly m_NavigationService As INavigationService

    Public Sub New(ByVal container As IUnityContainer, ByVal regionManager As IRegionManager, ByVal NavigationService As INavigationService)
        m_container = container
        m_rmShell = regionManager
        m_NavigationService = NavigationService
    End Sub


    Public Sub Initialize() Implements Microsoft.Practices.Composite.Modularity.IModule.Initialize
        RegisterViewsAndServices()
        ' Get reference to Controler
        Dim controller As ITeamSystemController = m_container.Resolve(Of ITeamSystemController)()
        ' Start Ball Roaling by adding views to the display
        m_NavigationService.EnsureBaseRegions()

        'm_NavigationService.AddButtonTool("Connect to Team System", controller.ConnectCommand, Nothing, RegionNames.Shell_Ribbon_HomeTab_CommunicationsGroup)
        'm_NavigationService.AddSeparatorTool()
        'm_NavigationService.RegisterMenuTool(RegionNames.TeamSystem_AppMenu_Main, "Team Server")
        'm_NavigationService.AddLabelTool("Configure settings for connecting to Team System.", RegionNames.TeamSystem_AppMenu_Main)
        'm_NavigationService.AddButtonTool("Connect to Team System", controller.ConnectCommand, Nothing, RegionNames.TeamSystem_AppMenu_Main)

        Dim TeamSystemHomeGroupPresenter As ITeamSystemHomeGroupPresenter = m_container.Resolve(Of ITeamSystemHomeGroupPresenter)()
        m_NavigationService.RegisterRibbonGroup("xxx1", CType(TeamSystemHomeGroupPresenter.View, RibbonGroup), RegionNames.Shell_Ribbon_HomeTab)
        TeamSystemHomeGroupPresenter.ShowView()

        Dim ConnectedToPresenter As IConnectedToPresenter = m_container.Resolve(Of IConnectedToPresenter)()
        m_NavigationService.AddTool(CType(ConnectedToPresenter.View, UIElement), RegionNames.Shell_StatusBar)
        ConnectedToPresenter.ShowView()



        ' Attempt to connect to the last state
        'controller.TryConnect() 'TODO: Implement Auto Conect
    End Sub

    Protected Sub RegisterViewsAndServices()
        ' Register Presentation Models
        m_container.RegisterType(Of ICredentialProviderPresentationModel, CredentialProviderPresentationModel)(New ContainerControlledLifetimeManager())
        m_container.RegisterType(Of ITeamSystemSelectionPresentationModel, TeamSystemSelectionPresentationModel)(New ContainerControlledLifetimeManager())
        ' Register Presenters
        m_container.RegisterType(Of ICredentialProviderPresenter, CredentialProviderPresenter)(New ContainerControlledLifetimeManager())
        m_container.RegisterType(Of IConnectedToPresenter, ConnectedToServerPresenter)(New ContainerControlledLifetimeManager())
        m_container.RegisterType(Of ITeamSystemHomeGroupPresenter, TeamSystemHomeGroupPresenter)(New ContainerControlledLifetimeManager())
        ' Register Views
        m_container.RegisterType(Of ICredentialProviderView, CredentialProviderView)()
        m_container.RegisterType(Of IConnectedToView, ConnectedToView)()
        m_container.RegisterType(Of ITeamSystemHomeGroupView, TeamSystemHomeGroupView)()

        ' Register Services
        m_container.RegisterType(Of ITeamServerService, TeamServerService)(New ContainerControlledLifetimeManager())
        ' Register Controlers
        m_container.RegisterType(Of ITeamSystemController, TeamSystemController)(New ContainerControlledLifetimeManager())
    End Sub




End Class
